package cn.jilian.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import cn.jilian.entity.Menu;


public interface MenuDAO extends PagingAndSortingRepository<Menu, Long>{

	@Query(value="select max(seq) as max from Menu where fid=?1 and rank=?2")
	Integer getMaxSeq(Long fid,Integer rank);
	
	List<Menu> findByFidOrderBySeq(Long fid);
	
	List<Menu> findByRank(Integer rank);
	
	@Modifying
	@Query(value="update bt_menu set seq=seq+?3 where fid=?1 and seq>=?2",nativeQuery=true)
	int offsetSeq(Long fid,Integer startSeq,Integer step);
	
	@Modifying
	@Query(value="update bt_menu set seq=seq+?4 where fid=?1 and seq>=?2 and seq<=?3",nativeQuery=true)
	int offsetSeq(Long fid,Integer startSeq,Integer endSeq,Integer step);
	
	@Modifying
	@Query(value="update bt_menu set seq=?1 where sid=?2",nativeQuery=true)
	int updateSeqBySid(Integer seq,Long sid);
}
